"use strict";
require("test").setup();

var Coroutine = require('coroutine');
var hash = require('hash');

var str_prefix = "ZG";

describe("user", function() {
    before(function() {

    });

    after(function() {
         clearDB();
    });


    it("登录", function() {
        httpPost("GET", "/v1.0/api/user/Sync", {})

        var t = "123"
        var result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "18888888888",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })
        console.error("登录  ", result)
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 2);
        assert.equal(result.data.role, "超级管理员");
        assert.equal(result.data.edited_password, true);
    });

    it("创建职工审批 ", function () {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张三明",
            gender:"男",
            phone:"15678967654",
            role:"职工",
            department:"肛肠科",
            staff_ic:"1589261",
            staff_hash:"1278646571",
            staff_attachments:JSON.stringify([111,2222,333]),
            created_by:"张老三"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        var result1 = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张三",
            gender:"女",
            phone:"15688887654",
            department:"内科",
            role:"职工",
            staff_ic:"1500261",
            staff_hash:"127864657",
            staff_attachments:JSON.stringify([1121,22322,3343]),
            created_by:"张老三"
        })
        assert.equal(result1.code, "200");
        assert.equal(result1.msg, "success");
    });

    //获取职工审批通过记录

    it("获取职工审批通过记录", function() {
        var result = httpPost("GET", "/v1.0/api/staffRecord/GetPassRecord?phone='15688887654'", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.have_pass_record, false);

    });

    it("职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
            status:"待审核",
            gender:"女"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,1);
        assert.equal(result.data.list[0].id,10002);
        assert.equal(result.data.list[0].name,"张三");
    });

    it("职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

      it("职工通过审批", function() {
          var result = httpPost("POST", "/v1.0/api/staffRecord/Pass", {
              id:10002,
          })

          assert.equal(result.code, "200");
          assert.equal(result.msg, "success");
          assert.equal(result.data.id,10002);
      });

    it("职工通过审批失效", function() {

        var result = httpPost("POST", "/v1.0/api/staffRecord/Invalid", {
            id:10002,
        })

        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

    it("职工拒绝审批", function() {

        var result = httpPost("POST", "/v1.0/api/staffRecord/Refuse", {
            id:10002,
        })

        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

      it("职工审批列表", function() {

          var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
          })
          assert.equal(result.code, "200");
          assert.equal(result.msg, "success");
          assert.equal(result.data.list.length,2);
      });


    it("获取职工审批详情", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Get", {
            id : 10002
        })
        console.error("获取职工审批详情1  :",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.getinfo.name, "张三");
    });

    it("update", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Update", {
            name:"张三",
            staff_id:10002,
            phone:"15688887654",
            hash:"127864657",
            to_update_hash:"14567"
        })
        console.error("update   ",result)
        assert.equal(result.code, "200");
    });

    it("获取职工审批详情", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Get", {
          id : 10002
        })
        console.error("获取职工审批详情  :",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.getinfo.name, "张三");
    });


    xit("创建职工", function() {
        var result = httpPost("POST", "/v1.0/api/user/Create", {
            "name": "张欧明",
            "gender": "男",
            "phone": "15609967654",
            "role": "职工",
            "department":"外科",
        })
        assert.equal(result.code, "200");
    });

    xit("职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
            status:"待审核",
            gender:"女"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,0);
    });

    xit("职工审批数量统计", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/SearchCount", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.reject_count, 1);
    });

    xit("H5创建职工审批", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5Create", {
            name :"张欧明",
            gender:"男",
            phone:"15609967654",
            department:"肛肠科",
            staff_ic:"1589261",
            staff_hash:"12464657",
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

    xit("H5List职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5List", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,3);
    });

    xit("职工通过审批", function() {

        var result = httpPost("POST", "/v1.0/api/staffRecord/Pass", {
            id:10004,
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.id,10004);
    });

   xit("审批操作记录", function() {

        var result = httpPost("POST", "/v1.0/api/operation/List", {

        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.result.length, 4);
    });

   xit("H5创建职工审批", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5Create", {
            name :"张欧明",
            gender:"男",
            phone:"15609967654",
            department:"肛肠科",
            staff_ic:"1589261",
            staff_hash:"12464657",
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });

    xit("职工审批失效", function() {

        var result = httpPost("POST", "/v1.0/api/staffRecord/Invalid", {
            id:10002,
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.id, 10002);
    });
//
    xit("H5创建职工审批", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5Create", {
            name :"张木明",
            gender:"男",
            phone:"15608867654",
            department:"肛肠科",
            staff_ic:"1589261",
            staff_hash:"12464657",
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });
//
    xit("职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,5);
    });
//
    xit("H5职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5List", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
    });
//
    xit("创建第三方职工审批 ", function () {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张儿明",
            gender:"男",
            phone:"15678097654",
            role:"第三方职工",
            department:"第三方部门",
            staff_ic:"1589261",
            staff_hash:"12464657",
            staff_attachments:JSON.stringify([111,2222,333]),
            created_by:"张老三"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        var result1 = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张亿三",
            gender:"女",
            phone:"15048887654",
            department:"第三方部门",
            role:"第三方职工",
            staff_ic:"1500261",
            staff_hash:"127864657",
            staff_attachments:JSON.stringify([1121,22322,3343]),
            created_by:"张老三"
        })
        assert.equal(result1.code, "200");
        assert.equal(result1.msg, "success");
    });

    xit("第三方职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
            "department":"第三方部门"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length, 2);
    });

    xit("第三方职工审批模糊查询", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
            "name":"张亿三",
            "department":"第三方部门"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length, 1);


        var result1 = httpPost("POST", "/v1.0/api/staffRecord/List", {
            "name":"张亿儿",
            "department":"第三方部门"
        })
        assert.equal(result1.code, "200");
        assert.equal(result1.msg, "success");
        assert.equal(result1.data.list.length, 0);
    });

    xit("H5创建第三方职工审批 ", function () {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5Create", {
            name :"张呕明",
            gender:"男",
            phone:"15678767654",
            role:"第三方职工",
            department:"第三方部门",
            staff_ic:"1589261",
            staff_hash:"12464657",
            staff_attachments:JSON.stringify([111,2222,333]),
            created_by:"张老三"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        var result1 = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张哦三",
            gender:"女",
            phone:"15076887654",
            department:"第三方部门",
            role:"第三方职工",
            staff_ic:"1500261",
            staff_hash:"127864657",
            staff_attachments:JSON.stringify([1121,22322,3343]),
            created_by:"张老三"
        })
        assert.equal(result1.code, "200");
        assert.equal(result1.msg, "success");
    });

    xit("H5第三方职工审批列表", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/H5List", {
            "department":"第三方部门"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length, 4);
    });
});

require('test').run();